﻿

using TianYuan.AutoMapper;
using TianYuan.Core.Caching;
using TianYuan.Core.Dependency;
using TianYuan.Core.Reflection;
using TianYuan.Data.Dapper;
using TianYuan.Redis;
using TianYuan.Web.Api.Dependency;
using TianYuan.Web.Mvc.Dependency;

namespace ApiDemo
{
    /// <summary>
    /// 依赖注入(IOC)容器初始化
    /// </summary>
    public static class CastleConfig
    {
        public static void Initialize()
        {
            //ICacheProvider provider = new RuntimeMemoryCacheProvider();
            //CacheManager.SetProvider(provider, CacheLevel.First);
            //redis缓存
            ICacheProvider provider = new RedisCacheProvider(new RedisClient(1, @"redis01.test.geely.com:6544,DefaultDatabase=2,password=pHlCvYMkPqi9tX$N"));

            CacheManager.SetProvider(provider, CacheLevel.First);
            //对象关系映射自动注册
            AutoMapperBootstrapper autoMapperBootstrapper = new AutoMapperBootstrapper(WebAssemblyFinder.Instance);
            autoMapperBootstrapper.Initialize();

            MvcBootstrapper mvcBootstrapper = new MvcBootstrapper(new ConventionalRegistrarConfig(true,true));
            ApiBootstrapper apiBootstrapper = new ApiBootstrapper(mvcBootstrapper.IocManager);
            DapperDataBootsrapper dapperDataBootsrapper = new DapperDataBootsrapper(mvcBootstrapper.IocManager);
            dapperDataBootsrapper.Initialize();
            apiBootstrapper.Initialize();
            //依赖注入初始化
            mvcBootstrapper.Initialize();
            
            //mvcBootstrapper.IocManager.Register<ISignInManager, IdentitySignInManager>(DependencyLifeStyle.Transient);
        }
    }
}